class WebAPIFunc(object):
    """
    Model:
    满足所有H5端Web下的接口函数

    Params:
    -env:odoo env
    """

    def __init__(self, env):
        self.env = env

    def ship_order_step_one(self, from_country, from_postcode, to_country, to_postcode, parcel_type_id):
        """
        Params:
        -from_country:起始国家
        -from_postcode:起始邮编
        -to_postcode:目的国家
        -parcel_type_id:包裹类型
        """
        values = {
            'send_country_id': from_country,
            'send_postal_code_id': from_postcode,
            'receive_country_id': to_country,
            'receive_postal_code_id': to_postcode,
            'package_type_id': parcel_type_id
        }
        response = self.env['rp.ship.order'].create([values])
        return response

    def ship_order_step_two(self, ship_order_code, parcel_list):
        rp_ship_order_record = self.env['rp.ship.order'].search([('code', '=', ship_order_code)])
        parcel_ids = []
        for parcel in parcel_list:
            # 单位
            weight_uom = self.env['uom.uom'].search([('name', '=', 'Kg')])
            length_uom = self.env['uom.uom'].search([('name', '=', 'cm')])
            values = {
                'rp_ship_order_id': rp_ship_order_record.id,
                'weight': parcel.weight.number,
                'weight_uom_id': weight_uom.id,
                'depth': parcel.long.number,
                'width': parcel.width.number,
                'height': parcel.height.number,
                'length_uom_id': length_uom.id
            }
            parcel = self.env['rp.parcel'].create([values])
            parcel_ids.append(parcel.id)
        rp_ship_order_record.write({'rp_parcel_ids': [(6, 0, parcel_ids)]})
        return rp_ship_order_record
